package rexsee.network;

import rexsee.core.browser.Browser;
import rexsee.core.browser.clazz.JavascriptInterface;

public class RexseeBluetoothPrinter implements JavascriptInterface {

	public static final String INTERFACE_NAME = "BluetoothPrinter";
	@Override
	public String getInterfaceName() {
		return mBrowser.application.resources.prefix + INTERFACE_NAME;
	}
	@Override
	public JavascriptInterface getInheritInterface(Browser childBrowser) {
		return this;
	}
	@Override
	public JavascriptInterface getNewInterface(Browser childBrowser) {
		return new RexseeBluetoothPrinter(childBrowser);
	}

	private final Browser mBrowser;
	private final RexseeBluetooth mBluetooth;

	public RexseeBluetoothPrinter(Browser browser) {
		mBrowser = browser;
		mBluetooth = (RexseeBluetooth) browser.interfaceList.get(browser.application.resources.prefix + RexseeBluetooth.INTERFACE_NAME);
	}

	private void bluetoothError() {
		mBrowser.exception(getInterfaceName(), "Printer Error: Bluetooth error is not found.");
	}

	public void init() {
		if (mBluetooth == null) {
			bluetoothError();
			return;
		}
		mBluetooth.writeASCII("27,64");
	}
	public void awake() {
		if (mBluetooth == null) {
			bluetoothError();
			return;
		}
		mBluetooth.writeASCII("0");
	}
	public void nextPage() {
		if (mBluetooth == null) {
			bluetoothError();
			return;
		}
		mBluetooth.writeASCII("12");
	}
	public void setToChinese() {
		if (mBluetooth == null) {
			bluetoothError();
			return;
		}
		mBluetooth.writeASCII("28,38");
	}
	public void setToEnglish() {
		if (mBluetooth == null) {
			bluetoothError();
			return;
		}
		mBluetooth.writeASCII("28,46");
	}

}
